package com.example.demo.controller;


import com.example.demo.ResBean.constant.ResCode;
import com.example.demo.entity.response.Response;
import com.example.demo.entity.sqlbean.Product;
import com.example.demo.service.ProductService;
import com.example.demo.utils.JsonUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
//@Api(tags ="产品接口")
@RestController
@RequestMapping("/product")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ProductController {


    @Autowired
    ProductService productService;

    @RequestMapping("select")
    public Response selectProduct(@RequestParam String data){
        Long projectId = Long.parseLong(JsonUtil.jsonToMap(data).get("projectId"));
        return productService.selectProductById(projectId);

    }


    @RequestMapping("details")
    public Response selectProductDetails(@RequestParam String data){
        Response response = new Response();
        Product product = JsonUtil.getInstance().jsonToBean(data, Product.class);
        if (product != null) {
            response = productService.selectProductByProduct(product);
        } else {
            response.setCode(ResCode.Param_ilegal_code);
            response.setMessage(ResCode.Param_ilegal_str);
        }
        return response;
    }



    
}
